package cn.jarlen.jwt.tools.crypt.device.soft;

import java.io.FileInputStream;
import java.io.FileOutputStream;

import cn.jarlen.jwt.tools.crypt.exception.CryptOperatorException;
import cn.jarlen.jwt.tools.crypt.operator.CryptOperator;

public class SoftCryptOperator implements CryptOperator {
    private static final SoftCryptOperator softCryptOperator = new SoftCryptOperator();

    public SoftCryptOperator() {
    }

    public static SoftCryptOperator getInstance() {
        return softCryptOperator;
    }

    public byte[] sm4Encrypt(byte[] key, byte[] data) {
        return SoftOperatorUtil.sm4Encrypt(key, data);
    }

    public boolean sm4Encrypt(byte[] key, FileInputStream fileInputStream, FileOutputStream fileOutputStream) {
        return SoftOperatorUtil.sm4Encrypt(key, fileInputStream, fileOutputStream);
    }

    public byte[] sm4Decrypt(byte[] key, byte[] cipherText) {
        try {
            return SoftOperatorUtil.sm4Decrypt(key, cipherText);
        } catch (Exception var4) {
            throw new CryptOperatorException(var4.getMessage());
        }
    }

    public boolean sm4Decrypt(byte[] key, FileInputStream fileInputStream, FileOutputStream fileOutputStream) {
        return SoftOperatorUtil.sm4Decrypt(key, fileInputStream, fileOutputStream);
    }

    public byte[] hmacSM3(byte[] key, byte[] data) {
        return SoftOperatorUtil.hmacWithSm3(key, data);
    }

    public byte[] hmacSM3(byte[] key, FileInputStream fileInputStream) {
        return SoftOperatorUtil.hmacWithSm3(key, fileInputStream);
    }

    public byte[] sm3(byte[] data) {
        return SoftOperatorUtil.sm3(data);
    }

    public byte[] sm3(FileInputStream fileInputStream) {
        return SoftOperatorUtil.sm3(fileInputStream);
    }
}
